package 集合进阶.单列集合.List集合.Set集合.TreeSet.练习;

public class Student implements Comparable<Student>{
    private String name;
    private int age;
    private double chineseScore;
    private double mathScore;
    private double englishScore;


    public Student() {
    }

    public Student(String name, int age, double chineseScore, double mathScore, double englishScore) {
        this.name = name;
        this.age = age;
        this.chineseScore = chineseScore;
        this.mathScore = mathScore;
        this.englishScore = englishScore;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    /**
     * 获取
     * @return chineseScore
     */
    public double getChineseScore() {
        return chineseScore;
    }

    /**
     * 设置
     * @param chineseScore
     */
    public void setChineseScore(double chineseScore) {
        this.chineseScore = chineseScore;
    }

    /**
     * 获取
     * @return mathScore
     */
    public double getMathScore() {
        return mathScore;
    }

    /**
     * 设置
     * @param mathScore
     */
    public void setMathScore(double mathScore) {
        this.mathScore = mathScore;
    }

    /**
     * 获取
     * @return englishScore
     */
    public double getEnglishScore() {
        return englishScore;
    }

    /**
     * 设置
     * @param englishScore
     */
    public void setEnglishScore(double englishScore) {
        this.englishScore = englishScore;
    }

    public String toString() {
        return "Student{name = " + name + ", age = " + age + ", chineseScore = " + chineseScore + ", mathScore = " + mathScore + ", englishScore = " + englishScore +
                ", Allscore ="+(int)(chineseScore+mathScore+englishScore)+ "}";
    }

    @Override
    /* this :表示要要添加的数据
        o: 表示在红黑树中已经存在的数据
        返回值: 负数:存在左边   正数: 右边   0:丢弃
     */
    public int compareTo(Student o) {
        double All=this.getChineseScore()+this.getMathScore()
                +this.getEnglishScore();
        double AllO=o.getChineseScore()+o.getMathScore()
                +o.getEnglishScore();
        double AllScore=All-AllO;
        //如果总分一样按照语文成绩排序
        AllScore=AllScore==0?this.getChineseScore()-o.getChineseScore():AllScore;
        //如果语文成绩也一样按照数学成绩排序
        AllScore=AllScore==0?this.getMathScore()-o.getMathScore():AllScore;
        //如果数学成绩还是一样按照英语成绩排
        AllScore=AllScore==0?this.getEnglishScore()-o.getEnglishScore():AllScore;
        //如果英语成绩一样按照年龄排
        AllScore=AllScore==0?this.getAge()-o.getAge():AllScore;
        //如果年龄还是一样按照按照字母的顺序排
        AllScore=AllScore==0?this.getName().compareTo(o.getName()):AllScore;
        return (int) AllScore;

    }
}
